var page = pagesize;
var curpage = 1;
var hasMore = true;
var footer = false;
var reset = true;
var orderKey = '';
$(function () {
    var key = getCookie('key');
    var name = getQueryString('act');
    if (!key) {
        window.location.href = WapSiteUrl + '/tmpl/member/login.html';
    }
    var username = '';

    function initPage() {
        if (reset) {
            curpage = 1;
            hasMore = true;
        }
        $('.loading').remove();
        if (!hasMore) {
            return false;
        }
        hasMore = false;
        $.ajax({
            type: 'post',
            url: ApiUrl + "/index.php?act=member_index&op=cash_withdraw_log&page=" + page + "&curpage=" + curpage,
            data: {key: key, name: name},
            dataType: 'json',
            success: function (result) {
                curpage++;
                hasMore = result.datas.log_list.hasmore;
                if (!hasMore) {
                    get_footer();
                }
                template.helper('formattime', function (nS) {
                    var d = new Date(parseInt(nS) * 1000);
                    var s = '';
                    s += d.getFullYear() + '年';
                    s += Appendzero((d.getMonth() + 1)) + '月';
                    s += Appendzero(d.getDate()) + '日 ';
                    s += Appendzero(d.getHours()) + ':';
                    s += Appendzero(d.getMinutes());
                    return s;
                });
                var res = result.datas;
                res.name = name;
                var html = template.render('log-list-tmpl', res);
                if (reset) {
                    reset = false;
                    $("#log_list").html(html);
                } else {
                    $("#log_list").append(html);
                }

            }
        });
    }


    function Appendzero(obj) {
        if (obj < 10) return "0" + obj; else return obj;
    }

    $('#filtrate_ul').find('a').click(function () {
        $('#filtrate_ul').find('li').removeClass('selected');
        $(this).parent().addClass('selected').siblings().removeClass("selected");
        reset = true;
        window.scrollTo(0, 0);
        initPage();
    });

    //初始化页面
    initPage();
    $(window).scroll(function () {
        if (($(window).scrollTop() + $(window).height() > $(document).height() - 1)) {
            initPage();
        }
    });
});

function get_footer() {
    if (!footer) {
        footer = true;
        $.ajax({
            url: WapSiteUrl + '/js/tmpl/footer.js',
            dataType: "script"
        });
    }
}